#include<bits/stdc++.h>
#define int long long
using namespace std;
namespace IO
{
	template<typename T>
	void read(T &_x){_x=0;int _f=1;char ch=getchar();while(!isdigit(ch)) _f=(ch=='-'?-1:_f),ch=getchar();while(isdigit(ch)) _x=_x*10+(ch^48),ch=getchar();_x*=_f;}
	template<typename T,typename... Args>
	void read(T &_x,Args&...others){Read(_x);Read(others...);}
	const int BUF=20000000;char buf[BUF],top,stk[32];int plen;
	#define pc(x) buf[plen++]=x
	#define flush(); fwrite(buf,1,plen,stdout),plen=0;
	template<typename T>inline void print(T x){if(!x){pc(48);return;}if(x<0) x=-x,pc('-');for(;x;x/=10) stk[++top]=48+x%10;while(top) pc(stk[top--]);}
}
using namespace IO;
const int N = 5e5+10,M = 2010;
int n,m,f[M][M],g[M][M],sum[N],l,r,a[N],x,y;
signed main()
{
	freopen("value.in","r",stdin);
	freopen("value.out","w",stdout);
	read(n);
	if(n <= 2010)
	{
		for(int i = 1;i <= n;i++) read(a[i]),f[i][i] = a[i]*a[i],g[i][i] = 1,sum[i] = sum[i-1]+a[i];
		for(int i = 1;i <= n;i++)
			for(int j = 1;j+i-1 <= n;j++)
			{
				int r = j+i-1;
				f[j][r] = (sum[r]-sum[j-1])*(sum[r]-sum[j-1]);
				g[j][r] = r-j+1;
				if(f[j][r-1]*g[j][r] > f[j][r]*g[j][r-1]) f[j][r] = f[j][r-1],g[j][r] = g[j][r-1];
				if(f[j+1][r]*g[j][r] > f[j][r]*g[j+1][r]) f[j][r] = f[j+1][r],g[j][r] = g[j+1][r];
			}
		for(int i = 1;i <= n;i++)
			for(int j = i;j <= n;j++)	
			{
				if(f[i][j] == 0) g[i][j] = 1;
				else
				{
					int x = __gcd(f[i][j],g[i][j]);
					f[i][j] /= x,g[i][j] /= x;
				}
			}
		read(m);
		while(m--)
		{
			read(l),read(r);
			print(f[l][r]),pc(' '),print(g[l][r]),pc('\n');
			flush(); 
		}	
		return 0;
	}
	for(int i = 1;i <= n;i++) read(a[i]),sum[i] = sum[i-1]+a[i];
	read(m);
	while(m--)
	{
		read(l),read(r); 
		x = sum[r]-sum[l-1],y = r-l+1;
		if(x == 0) y = 1;
		else 
		{
			int z = __gcd(x,y);
			x /= z,y /= z;
		} 
		print(x),pc(' '),print(y),pc('\n');
		flush(); 
	}
	return 0;
}



